package com.guigu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 认证 方式二
 */
//@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        //对密码加密
        BCryptPasswordEncoder passwordEncoder=new BCryptPasswordEncoder();
        String pwd = passwordEncoder.encode("123");
        //设置用户名 密码 权限
        auth.inMemoryAuthentication().withUser("zs").password(pwd).roles("admin");
    }

    //@Bean
    PasswordEncoder password(){
        return new BCryptPasswordEncoder();
    }
}
